<?php
    require_once("./classes/sessao.php");
    require_once("./classes/interfaces.php");
    require_once("./classes/conexao.php");

    session_start();

    if (isset($_SESSION['ANAWEB']))
    {
        //$_SESSION['ANAWEB']->AlteraModo("gerenciabib");
        //$_SESSION['ANAWEB']->AlteraAmbiente("gerenciabib");
    }
    if (!isset($_SESSION['ANAWEB']) || $_SESSION['ANAWEB']->RetornaIdioma() == "PT_BR")
    {
        $msg = new Traducao("/home/projetos/anaweb/anaweb-new/linguas/linguas.xml", "pt-br");
        //include_once("PT_BR.php");
    }
    else
    {
        $msg = new Traducao("/home/projetos/anaweb/anaweb-new/linguas/linguas.xml", "en-us");
        //include_once("EN_US.php");
    }
    $pagina = new Interfaces();
    $pagina->Header( "ANAWEB ");
    $pagina->Body();
?>
            <h1><?php echo $msg->get('Gerenciar_Bibliotecas') ?></h1>
<?php
    if (isset($_SESSION['ANAWEB']) && $_SESSION['ANAWEB']->RetornaTipoUsuario() == "professor")
    {
?>
            <p><a href="criarbiblioteca.php"><?php echo $msg->get('Criar_Biblioteca') ?></a> | <a href="colaborarbiblioteca.php"><?php echo $msg->get('Colaborar_Biblioteca') ?></a></p>
<?php
        $conexao = new Conexao();
        $conexao->Conecta();
        $result = $conexao->Executa("SELECT * FROM biblioteca WHERE id_professor = ".$_SESSION['ANAWEB']->RetornaId());
        while ($res = $result->FetchRow())
        {
            $prof = $conexao->Executa("SELECT * FROM usuario WHERE id_usuario = ".$res['id_professor']);
            $prof = $prof->FetchRow();
?>
            <hr>
            <h2>Biblioteca <?php echo $res['NomeBiblioteca'] ?> <a href="removerbiblioteca.php?id=<?php echo $res['id_biblioteca'] ?>"><img alt="Remover biblioteca" src="./imagens/button_drop.png"></a></h2>
            <p>Respons&aacute;vel: <?php echo $prof['nome_usuario'] ?></p>
<?php
            $requisicoes = $conexao->Executa("SELECT * FROM requisicoes_bib WHERE id_bib = ".$res['id_biblioteca']);
            while ($req = $requisicoes->FetchRow())
            {
                $usuario = $conexao->Executa("SELECT * FROM usuario where id_usuario = ".$req['id_user']);
                if ($usr = $usuario->FetchRow())
                {
?>
            <form name="formautorizaruser<?php echo $usr['id_usuario'] ?>" action="autorizarusuario.php" method="post">
            <?php echo $msg->get('Autorizar_Usuario1') ?> <?php echo $usr['nome_usuario'] ?> <?php echo $msg->get('Autorizar_Usuario2') ?><br>
            <input type="hidden" name="idbib" value="<?php echo $res['id_biblioteca'] ?>">
            <input type="hidden" name="idusuario" value="<?php echo $usr['id_usuario'] ?>">
            <input type="submit" name="permitir" value="Sim"> <input type="submit" name="permitir" value="Nao">
            </form>
<?php
                }
            }

            $colaboradores = $conexao->Executa("SELECT * FROM colaborador_biblioteca WHERE id_bib = ".$res['id_biblioteca']);
            if ($colab = $colaboradores->FetchRow())
            {
?>
            <p>Colaborador(es):</p>
            <p>
<?php
                do {
                    $usercolab = $conexao->Executa("SELECT * FROM usuario WHERE id_usuario=".$colab['id_user']);
                    if ($usr_colab = $usercolab->FetchRow())
                    {
?>
            <?php echo $usr_colab['nome_usuario'] ?><br>
<?php
                    }
                } while ($colab = $colaboradores->FetchRow());
?>
            </p>
<?php
            }
        }
?>
<?php
    }
    $pagina->Footer();
?>
